package com.daodway.designpattern.statepattern;

public class CookStew extends State<MinersWife> {
	private static CookStew instance;
	private CookStew(){}
	public static CookStew instance(){
		if(instance==null){
			instance=new CookStew();
		}
		return instance;
	}
	@Override
	public void Enter(MinersWife t) {
		System.out.println(t.entityName+":"+"Hi honey.Let e make you some of mah fine country stew");
		MessageDispatcher.Instance().DispatchMessage(2000l, t.ID(), t.ID(), MsgType.Msg_StewReady.getValue(), "");
		
	}

	@Override
	public void Execute(MinersWife t) {
		if(!t.isCooking()){
			System.out.println(t.entityName+":"+"Puttin the Stew in the oven");
			
			
		}
		t.setCooking(true);
	}

	@Override
	public void Exit(MinersWife t) {
		System.out.println(t.entityName+":"+"Fussing over food");
	}

	@Override
	public boolean OnMessage(MinersWife t, Telegram msg) {
		switch (msg.Msg) {
			case 2:{
				System.out.println("Stew ready!Let's eat");
				MessageDispatcher.Instance().DispatchMessage(0, t.ID(), 1, MsgType.Msg_StewReady.getValue(), "");
				t.setCooking(false);
				t.ChangeState(DoHouseWork.Instance());
			}	
			return true;
		}
		return false;
	}

}
